% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/state_from_s2b_bysite.R
\name{state_from_s2b_bysite}
\alias{state_from_s2b_bysite}
\title{Get State each site is entirely within, quickly, from table of blockid, ejam_uniq_id}
\usage{
state_from_s2b_bysite(sites2blocks)
}
\arguments{
\item{sites2blocks}{data.table or data.frame, like \link{testoutput_getblocksnearby_10pts_1miles},
from \code{\link[=getblocksnearby]{getblocksnearby()}} that has columns ejam_uniq_id and blockid and distance}
}
\value{
data.table with columns  ejam_uniq_id, ST
}
\description{
Find the 2-character State abbreviation, but only for sites entirely in 1 state.
}
\details{
This only works for sites entirely in 1 state.
For multistate sites, need lat/lon of site and that is slower.
This returns NA for any site whose nearby blocks are in multiple states.
For multistate sites, you need to know the lat/lon of the site to be sure of its state.

This function is for when you need to quickly find out the state each site is in,
to be able to report state percentiles, This can identify the State
each site is located in, based on the states of the nearby blocks (and parent blockgroups).
In many analyses, all the sites will be single-state sites, and this function will be sufficient.

However, for the rare edge case where you did not save the lat,lon of sites you analyzed,
you would need to approximate those from the lat/lon of the blocks and their distances,
via latlon_from_s2b(), separately.

These two functions differ -- one gets the state info for each unique site,
and the other gets the state abbreviation of each unique block:
Note: unexported function
xx = state_from_s2b_bysite(testoutput_getblocksnearby_10pts_1miles)[]
NROW(xx)
\link{1} 10
length(unique(testoutput_getblocksnearby_10pts_1miles$ejam_uniq_id))
\link{1} 10

length(EJAM:::state_from_blockid_table(testoutput_getblocksnearby_10pts_1miles))
\link{1} 1914
NROW(testoutput_getblocksnearby_10pts_1miles)
\link{1} 1914
}
\examples{
\dontrun{
# unexported function
table(state_from_blockid_table(testoutput_getblocksnearby_10pts_1miles))
state_from_s2b_bysite(testoutput_getblocksnearby_10pts_1miles)[]

  x = getblocksnearby(pts, radius = 30)
  y = state_from_s2b_bysite(x)
  table(y$in_how_many_states)
  y

  fname = './inst/testdata/testpoints_207_sites_with_signif_violations_NAICS_326_ECHO.csv'
  x = state_from_s2b_bysite(
    getblocksnearby( latlon_from_anything(fname), quadtree = localtree))
  y = read_csv_or_xl(fname)
  x$ST == y$FacState
  }
  state_from_s2b_bysite(testoutput_getblocksnearby_10pts_1miles) 

}
\seealso{
\code{\link[=state_from_blockid_table]{state_from_blockid_table()}} \code{\link[=state_per_site_for_doaggregate]{state_per_site_for_doaggregate()}}
}
\keyword{internal}
